package test;

import bean.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author 飞哥
 * @version V1.0
 * @package test
 * @date 2021/7/4 14:27
 */
public class MyApp02 {
    public static void main(String[] args) throws IOException {
        InputStream is = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(is);
        SqlSession sqlSession = factory.openSession();
        String sqlId = "dao.StudentDao.queryStudentById";

        Student student = sqlSession.selectOne(sqlId);
        List<Student> list = sqlSession.selectList("dao.StudentDao.queryStudents");

        for (Student student1 : list) {
            System.out.println(student1);
        }
        System.out.println(student);
    }
}
